package blue.starter.internal.httpclient.util;

import java.util.Collection;

/**
 * 字符串工具类
 *
 * @author zhengj
 * @date 2009-2-15
 * @date 1.0
 * @since 1.0
 */
public class StringUtil
{
	private StringUtil()
	{
	}

	/**
	 * 连接字符串
	 *
	 * @param list 字符串列表
	 * @param separator 分割符
	 * @return 连接后的字符串
	 */
	public static String join(Collection<?> list, String separator)
	{
		if (list == null || list.isEmpty())
			return null;

		String sep = separator == null ? "" : separator;
		StringBuilder concat = new StringBuilder();
		for (Object obj : list)
		{
			concat.append(obj).append(sep);
		}
		if (concat.length() > sep.length())
		{
			concat.delete(concat.length() - sep.length(), concat.length());
		}
		return concat.toString();
	}

}
